﻿using System;
using System.Collections;
using System.Windows.Forms;
using GuidanceExplorerAddIn.Controls;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;

namespace GuidanceExplorerAddIn.Windows
{
//    [Guid("59325CE6-0410-4da9-B2F9-B153417BC096")]
    public class GEWindow : ToolWindowPane
    {
        private GETreeView treeView;
        private SelectionContainer selectionContainer;

        public GEWindow() :  base(null)
        {
            
            this.Caption = "Guidance Explorer";//Resources.ToolWindowTitle;
            this.BitmapResourceID = 301;
            this.BitmapIndex = 1;

            treeView = new GETreeView(this);
            selectionContainer = new Microsoft.VisualStudio.Shell.SelectionContainer();
        }

        public GETreeView TreeView
        {
            get
            {
                return treeView;
            }
        }

        override public IWin32Window Window
        {
            get
            {
                return (IWin32Window)treeView;
            }
        }

        //public override void OnToolWindowCreated()
        //{
        //    selectionContainer = new Microsoft.VisualStudio.Shell.SelectionContainer();
        //}



        public virtual void OnSelectionChange(ICollection selectedObjects)
        {
            try
            {
                IVsTrackSelectionEx trackSelection = this.GetService(typeof(SVsTrackSelectionEx)) as IVsTrackSelectionEx;
                if (trackSelection != null)
                {
                    selectionContainer.SelectedObjects = selectedObjects;
                    selectionContainer.SelectableObjects = selectedObjects;
                    trackSelection.OnSelectChange((ISelectionContainer)selectionContainer);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }

}